<template>
	<view class="">
		<view class="popup-content">
			<!-- 校区搜索和排序 -->
			<u-gap height="20rpx" bgColor="#f0f0f0"></u-gap>
			<view class="search-sort">
				<view class="search-box">
					<!-- <u-search @search="search" @custom="onSearch2" placeholder="搜索校区" :showAction="false"
						v-model="searchKey2" shape="square" bgColor="#fff" @focus='onfocus2' @blur='onblur2'>
					</u-search> -->
					<u-search v-model="searchKey3" placeholder="搜索" bgColor="#fff" @search="onSearch3"
						:show-action="false" shape="square" />
				</view>
				<view class="" v-if="onif2 == true">
					<view v-if="filteredList2.length > 0" class="list-container2">
						<scroll-view scroll-y class="list">
							<view v-for="(item, index) in filteredList2" :key="index" class="list-item"
								@click="selectItem2(item)">
								<view class="" :class="[item.id ===Itemid2?'card_jec':'card_je']">
									{{ item.venue_name }}
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
				<!-- <view class="sort-btn" @click="toggleSort">
					<uni-icons :type="sortOrder === 'asc' ? 'arrow-up' : 'arrow-down'" size="14"
						color="#666"></uni-icons>
					<text class="sort-text">{{ sortOrder === 'asc' ? '升序' : '降序' }}</text>
				</view> -->
				<view class="" style="height: 50rpx;">
					<image @click="showsclick()"
						src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/c154ba8794158495ff83ed092dc0fad167ff2406.png"
						style="width: 80rpx;height: 40rpx;" mode=""></image>
				</view>
				<view class="box_20" v-if="sortOrder === 'desc'">
					<view class=""
						style="display: flex;flex-direction: row;justify-content: space-around;margin-bottom: 20rpx;">
						<view class="image-text_6" style="margin-right: 20rpx;" @click="shanchu(1)">
							<uni-icons type="arrow-down" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生人数降序</text>
						</view>
						<view class="image-text_6" @click="shanchu(2)">
							<uni-icons type="arrow-up" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生人数升序</text>
						</view>
					</view>
					<view class="" style="display: flex;flex-direction: row;margin-bottom: 20rpx;">
						<view class="image-text_6" style="margin-right: 20rpx;" @click="shanchu(3)">
							<uni-icons type="arrow-down" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生进度降序</text>
						</view>
						<view class="image-text_6" @click="shanchu(4)">
							<uni-icons type="arrow-up" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生进度升序</text>
						</view>
					</view>
					<view class="" style="display: flex;flex-direction: row;">
						<view class="image-text_6" style="margin-right: 20rpx;" @click="shanchu(5)">
							<uni-icons type="arrow-down" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生金额降序</text>
						</view>
						<view class="image-text_6" @click="shanchu(6)">
							<uni-icons type="arrow-up" size="14" color="#ffffff"></uni-icons>
							<text lines="1" class="text-group_6">招生金额升序</text>
						</view>
					</view>
					<image
						src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/f820809dedb1e84b45f4b46e359e3ad308af5541.png"
						class="image_4"></image>
				</view>
			</view>
			<view class="popup-body">
				<view v-for="(activity,index) in ordersList" :key="index" class="activity-card" @click="ontraininglist(activity)">
					<view class="activity-header">
						<text class="activity-name">{{ activity.name }}</text>
					</view>
					
					<view class="activity-content">
						<view class="image">
							<!-- <u--image width="100%" height="250rpx" :src="item.cover != null ? item.cover : pic_img" radius="5"></u--image> -->
							<view
								style="width: 100%;height: 250rpx;background-color: #EDF5F5;display: flex;lex-direction: row; justify-content: center; align-items: center;">
								<image style="width: 100%;height: 250rpx;" :src="activity.cover" mode="aspectFit">
								</image>
							</view>
						</view>
						<view class="activity-info">
							<view class="" style="display: flex; flex-direction: row; align-items: center;">
								<view class="tag flex-align">
									{{ activity.course_name }}
								</view>
								<view class="tag flex-align">
									{{ activity.train_program_name }}
								</view>
							</view>
							<view
								style="font-size: 24rpx;color: #4E6EAF;display: flex; flex-direction: row; ">
								<view class="tags flex-align">
									{{ activity.train_enum_name }}
								</view>
								<view class="">
									{{activity.area_name}}
								</view>
							</view>
							<text class="date-range">{{ activity.display_start }}{{ activity.display_end }}</text>
							<view class="activity-progress">
								<text
									class="progress-text">已报名：{{ activity.enroll_cnt }}/{{ activity.total_stock }}，剩余：{{ activity.less_stock }}</text>
								<view class="" style="height: 30rpx;width: 100%;margin-top: 10rpx;">
									<u-line-progress :percentage="activity.percent" activeColor="#00aa7f"
										:showText="true"></u-line-progress>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="" style="width: 100%;height: 60rpx;">

				</view>
			</view>
		</view>
	</view>
</template>
<script>
	const personal = require("@/api/personal/index.js");
	import navbar from '@/mixins/navbar.js';
	export default {
		mixins: [navbar({
			navBarColor: '#fff'
		})],
		data() {
			return {
				campusActivities: [{
						id: 1,
						name: '暑期游学营',
						status: '进行中',
						enrolled: 45,
						total: 50,
						dateRange: '2024-07-01 至 2024-08-31',
						image: 'https://ai-public.mastergo.com/ai/img_res/e4b925607553738270771589257b38c7.jpg'
					},
					{
						id: 2,
						name: '全科辅导班',
						status: '进行中',
						enrolled: 28,
						total: 40,
						dateRange: '2024-06-01 至 2024-12-31',
						image: 'https://ai-public.mastergo.com/ai/img_res/3ed63e3a5031c62a50c920953a65307f.jpg'
					},
					{
						id: 3,
						name: '英语特训营',
						status: '即将开始',
						enrolled: 15,
						total: 30,
						dateRange: '2024-06-15 至 2024-09-15',
						image: 'https://ai-public.mastergo.com/ai/img_res/3a9608609815dc97575f199e3af88d31.jpg'
					},

				],
				id: '',
				venue_id: '',
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				ordersList: [],
				searchKey2: '', // 搜索关键词
				originalList2: [],
				filteredList2: [], // 过滤后的列表，用于展示
				selectedItem2: null, // 选中项的数据
				onif2: false,
				sortOrder: "asc",
				searchKey3: '',
				sort: 1,
			}
		},
		onLoad(options) {
			console.log(options, 'options')
			this.venue_id = options.venue_id
			this.id = options.id
			this.area_info()
			uni.setNavigationBarTitle({
				title: options.area_name
			});
		},
		methods: {
			ontraininglist(activity){
				uni.navigateTo({
					url: `./traininglist?selectionArr=${encodeURIComponent(JSON.stringify(activity))}` + "&venue_id=" + this.venue_id + "&atstus=" + 1
				})
			},
			// 搜索事件处理
			onSearch3(value) {
				this.searchKey3 = value
				this.area_info()
			},
			// 搜索事件处理
			onSearch2(value) {
				console.log(value, 'value')
				this.filterList2(value);
			},
			// 选择列表项事件处理
			selectItem2(item) {
				console.log(item, 'item')
				this.onif2 = false
				this.selectedItem2 = item;
				this.searchKey2 = item.venue_name; // 可选：将搜索关键词设置为选中项的名称
				this.Itemid2 = item.id
				// 可以在此处添加其他逻辑，如关闭搜索结果列表等
				this.area_info()
			},
			onclear2() {
				this.hylist = []
				this.searchKey2 = ''
				this.Itemid2 = ''
				this.area_info()
			},
			// 过滤列表方法
			filterList2(key) {
				if (key) {
					this.filteredList2 = this.originalList2.filter(item =>
						item.venue_name.includes(key)
					);
				} else {
					this.filteredList2 = this.originalList2;
				}
			},
			onfocus2(value) {
				console.log(value, 'valuevalue111')
				this.onif2 = true
			},
			onblur2(value) {
				console.log(value, 'valuevalue222')
				this.onif2 = false
			},
			shanchu(type) {
				this.sort = type
				this.sortOrder = 'asc'
				this.area_info()
			},
			showsclick() {
				this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
			},
			async area_info() {
				let that = this;
				// if (this.listQuery.pageNo === 1) that.ordersList = [];
				let params = {
					venue_id: this.venue_id,
					area_id: this.id,
					keyword: this.searchKey3,
					sort: this.sort,
					// page: this.listQuery.pageNo,
					// pageSize: this.listQuery.pageSize,
				};
				let res = await personal.area_info(params);
				if (res.code == 1) {
					that.ordersList = res.data.list
					// that.ordersList = that.ordersList.concat(res.data.list.data); //将数据拼接在一起
					// that.totalPage = res.data.list.last_page
				}
			},
			// 下拉刷新
			// onReachBottom() {
			// 	// uni.showLoading({
			// 	// 	title: '加载中'
			// 	// });
			// 	if (this.totalPage <= this.listQuery.pageNo) {
			// 		// uni.hideLoading();
			// 		uni.showToast({
			// 			title: '没有更多了',
			// 			duration: 2000,
			// 			icon: 'none'
			// 		});
			// 		return
			// 	}
			// 	this.listQuery.pageNo += 1;
			// 	this.area_info()
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.box_20 {
		background-color: rgba(62, 62, 62, 1.0);
		border-radius: 10rpx;
		position: absolute;
		width: 300rpx;
		height: 200rpx;
		flex-direction: column;
		display: flex;
		right: 22px;
		top: 80rpx;
		z-index: 998;
		justify-content: center;
		align-items: center;

		.image-text_4 {
			width: 34rpx;
			height: 62rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin: 20rpx 0 0 28rpx;
		}

		.icon_5 {
			width: 30rpx;
			height: 30rpx;
			margin-left: 2rpx;
		}

		.text-group_4 {
			width: 34rpx;
			height: 18rpx;
			overflow-wrap: break-word;
			color: rgba(255, 255, 255, 1);
			font-size: 18rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 24rpx;
			margin-top: 14rpx;
		}

		.image-text_5 {
			width: 36rpx;
			height: 65rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin: 17rpx 0 0 37rpx;
		}

		.icon_67 {
			width: 32rpx;
			height: 32rpx;
			margin-left: 2rpx;
		}

		.text-group_5 {
			width: 36rpx;
			height: 18rpx;
			overflow-wrap: break-word;
			color: rgba(255, 255, 255, 1);
			font-size: 18rpx;
			font-family: PingFang-SC-Medium;
			font-weight: 500;
			text-align: left;
			white-space: nowrap;
			line-height: 24rpx;
			margin-top: 15rpx;
		}

		.image-text_6 {
			width: 140rpx;
			height: 40rpx;
			background-color: rgba(255, 255, 255, 0.4);
			border-radius: 5rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			justify-content: space-around;
		}

		.icon_7 {
			width: 32rpx;
			height: 32rpx;
			margin-left: 2rpx;
		}

		.text-group_6 {
			overflow-wrap: break-word;
			color: rgba(255, 255, 255, 1);
			font-size: 18rpx;
			font-weight: 500;
			white-space: nowrap;
		}

		.image_4 {
			position: absolute;
			right: 10rpx;
			top: -13rpx;
			width: 28rpx;
			height: 14rpx;
		}
	}

	.search-sort {
		display: flex;
		align-items: center;
		gap: 20rpx;
		margin: 30rpx 0;
		position: relative;
		padding: 0 30rpx;

		.list-container2 {
			max-height: 300rpx;
			overflow-y: auto;
			box-shadow: 0 0 18rpx 8rpx hsla(0, 0%, 40%, .1);
			border-radius: 4rpx;
			padding: 10rpx;
			background-color: #fff;
			position: fixed;
			z-index: 999;
			top: 780rpx;
			left: 40rpx;
			width: 300rpx;
			font-size: 28rpx;

		}

		.list {
			height: 100%;
		}

		.list-item {
			padding: 15rpx;
			// border-bottom: 1px solid #eee;
			cursor: pointer;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			font-size: 30rpx;
		}

		.card_jec {
			color: rgb(13, 132, 255);
		}

		.card_je {
			color: #000000;
		}

		.list-item:last-child {
			border-bottom: none;
		}

		.list-item:hover {
			background-color: #f5f5f5;
		}
	}

	.container {
		display: flex;
		flex-direction: column;
		min-height: 100%;
	}

	.header {
		background-color: #f0f0f0;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 100;
	}

	.header-content {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
		height: 88rpx;
	}

	.title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
	}

	.date {
		font-size: 26rpx;
		color: #666;
	}

	.main {
		margin-top: 88rpx;
		padding: 30rpx;
	}

	.overview {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
		margin-bottom: 30rpx;
	}

	.total-card {
		background: #ffffff;
		padding: 30rpx;
		border-radius: 12rpx;
		box-shadow: 0 2px 8rpx rgba(0, 0, 0, 0.05);
	}

	.overview-grid {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		gap: 20rpx;
	}

	.overview-item {
		background: #ffffff;
		padding: 30rpx;
		border-radius: 12rpx;
		box-shadow: 0 2px 8rpx rgba(0, 0, 0, 0.05);
	}

	.label {
		font-size: 26rpx;
		color: #666;
	}

	.value-container {
		display: flex;
		align-items: center;
		margin-top: 16rpx;
	}

	.value {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}

	.change {
		font-size: 24rpx;
		margin-left: 16rpx;
	}

	.up {
		color: #2ecc71;
	}

	.down {
		color: #e74c3c;
	}

	.search-sort {
		display: flex;
		align-items: center;
		gap: 20rpx;
		margin: 30rpx 0;
	}

	.search-box {
		flex: 1;
	}

	.sort-btn {
		display: flex;
		align-items: center;
		gap: 8rpx;
		background: #ffffff;
		padding: 16rpx 24rpx;
		border-radius: 100rpx;
	}

	.sort-text {
		font-size: 26rpx;
		color: #666;
	}

	.campus-list {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.campus-card {
		background: #ffffff;
		padding: 30rpx;
		border-radius: 12rpx;
		box-shadow: 0 2px 8rpx rgba(0, 0, 0, 0.05);
	}

	.campus-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.rank {
		display: flex;
		align-items: center;
		gap: 8rpx;
	}

	.rank-text {
		font-size: 26rpx;
		color: #999;
	}

	.campus-title {
		display: flex;
		align-items: center;
		gap: 12rpx;
	}

	.campus-name {
		font-size: 32rpx;
		font-weight: 500;
		color: #3498db;
	}

	.campus-details {
		display: flex;
		align-items: center;
		gap: 40rpx;
	}

	.progress-circle {
		flex-shrink: 0;
		width: 120rpx;
		height: 120rpx;
	}

	.detail-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		gap: 16rpx;
	}

	.enrollment-info {
		display: flex;
		justify-content: space-between;
	}

	.info-text {
		font-size: 26rpx;
		color: #666;
	}

	.activity-info {
		display: flex;
		justify-content: flex-end;
		// align-items: center;
		gap: 8rpx;
	}
	
	
	.tag {
		font-size: 22rpx;
		color: #2F75FA;
		background-color: #d5e3fe;
		border-radius: 8rpx;
		padding: 5rpx 10rpx;
		margin-right: 20rpx;
	}
	
	.tags {
		font-size: 22rpx;
		color: #2F75FA;
		background-color: #d5e3fe;
		border-radius: 8rpx;
		padding: 5rpx 10rpx;
		margin-right: 20rpx;
	}

	.activity-text {
		font-size: 26rpx;
		color: #666;
	}

	.popup-content {
		background: #f3f3f3;
		width: 100%;
		height: 100vh;
		border-radius: 20rpx;
		// overflow: hidden;
	}

	.popup-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 2rpx solid #f0f0f0;
	}

	.popup-title {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
	}

	.popup-body {
		padding: 0 30rpx;
	}

	.activity-card {
		background: #ffffff;
		padding: 24rpx;
		border-radius: 12rpx;
		box-shadow: 0 2px 8rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 20rpx;
	}

	.activity-content {
		display: flex;
		gap: 20rpx;
		margin-top: 20rpx;
	}

	.image {
		width: 200rpx;
		height: 100%;
		border-radius: 7rpx;
		// overflow: hidden;
		position: relative;

		/deep/ .u-transition {
			width: 100%;
			height: 100%;
		}

		.image-info {
			position: absolute;
			bottom: 0;
			width: 100%;
			left: 0;
			font-size: 24rpx;
			text-align: center;
			color: white;
			padding: 10rpx 0;
			background-color: rgba(0, 0, 0, 0.5);
		}
	}

	.activity-image {
		width: 200rpx;
		height: 160rpx;
		border-radius: 8rpx;
		flex-shrink: 0;
	}

	.activity-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		gap: 16rpx;
	}

	.date-range {
		font-size: 24rpx;
		color: #666;
	}

	.activity-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.activity-name {
		font-size: 28rpx;
		font-weight: 500;
		color: #333;
	}

	.status-tag {
		font-size: 24rpx;
		padding: 6rpx 16rpx;
		border-radius: 100rpx;
	}

	.active {
		background: #e8f6e9;
		color: #2ecc71;
	}

	.pending {
		background: #f5f5f5;
		color: #999;
	}

	.activity-progress {
		display: flex;
		flex-direction: column;
		gap: 12rpx;
	}

	.progress-text {
		font-size: 26rpx;
		color: #666;
	}

	.progress-bar-container {
		width: 100%;
		height: 16rpx;
		background: #f5f5f5;
		border-radius: 100rpx;
		overflow: hidden;
	}

	.progress-bar {
		height: 100%;
		border-radius: 100rpx;
		transition: width 0.3s ease;
	}
</style>